package com.ag.utils.param.verify;

import com.ag.exception.InvalidParamException;
import com.ag.utils.param.IVerifyAndConvertValue;

public class DoubleVerifyAndConvertValue implements IVerifyAndConvertValue {
	@Override
	public Object getValue(Object value, String viewName, Object defaultValue) {
		String valueOf = value == null ? null : String.valueOf(value);
		try {
			return Double.valueOf(valueOf);
		} catch (Exception e) {
			if(defaultValue != null) {
				return defaultValue;
			} else {
				throw new InvalidParamException(viewName + "不是一个浮点数.");
			}
		}
	}
}